package com.lee.boot.head.first.demo.repository;

import com.lee.boot.head.first.demo.entity.UserEntity;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;


/**
 * @Auther: Lee
 * @Date: 2018/4/27 16:34
 * @Description:暂时注释掉jpa
 */

public interface UserRepository extends JpaRepository<UserEntity, Long>, JpaSpecificationExecutor<UserEntity>, Serializable {

    /**
     * 自定义sql
     * 站位符？后面的1位参数下标 以1开头
     * <p>
     * 根据用户名查user
     *
     * @param username
     * @return
     */
    @Query(value = "select * from user where username = ?1", nativeQuery = true)
    public List<UserEntity> selectByUsername(String username);

    /***
     * 根据用户名和密码删除记录
     * @param username
     * @param password
     */
    @Transactional
    @Modifying
    @Query(value = "DELETE FROM user WHERE username = ?1 AND password = ?2", nativeQuery = true)
    void deleteByNameAndPassword(String username, String password);
}
